<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');	
 
class MY_Controller extends CI_Controller 
{
 	protected $data = array() ;

	function __construct()
    {
        parent::__construct();
		//<!--quoc them-->/////////////////////////////////////////////////////////
		$this->load->model("Events_model");
		$this->load->library('session');
		$autoload['libraries']=array('database','session');	
		
		 		
	}
	protected function loadadmin()
	{
		$TaiKhoan = $this->session->userdata('TaiKhoan');
		if(empty($TaiKhoan)) 
		{
			redirect("/TrangChu/DangNhap", 'refresh');
		}elseif($TaiKhoan['Quyen']!=1)
		{
			redirect("/TrangChu/index", 'refresh');
		}
		$this->load->helper(array('url','form'));	
		$this->load->view('layout/header',$this->data);
		$this->load->view('layout/body');
		
	}	
	protected function loadtrangchu($lang)
	{
		$this->load->helper(array('url','language'));
		if( $lang<>""){
			$lang_code =$lang;
			$languages = array('en','vi');
		}
		else{
			$lang_code = $this->uri->segment(1);
			$languages = array('en','vi');
		}	 
		if (in_array($lang_code, $languages))
		{
			$this->config->set_item('language',$lang_code);
			$this->data['language']=$lang_code;
		}else
		{
			$this->data['language']='vi';
		} 
		$this->lang->load('site');
		$this->load->helper('form'); 
		$this->load->library('cart'); 
		$this->load->database();
		$this->load->model('Danhmuc_model');
		$this->load->model('SanPhan_TrangChu');
		 
		$this->data['danhmucs']=$this->Danhmuc_model->getresult_vi_en(); 
		$this->data['danhmuc']=$this->Danhmuc_model->LayDM(); 
		$this->data['SP_Top2']=$this->SanPhan_TrangChu->LayTop2(); 
	}		
	// LoadPage('trangchu/menu',$this->data)
	public function LoadPage($Ham,$Bien){
		$this->load->view('trangchu/header',$Bien);
		$this->load->view('trangchu/menu',$Bien);
		$this->load->view($Ham,$Bien); 
		$this->load->view('trangchu/Footer',$Bien);
 	}
	public function LayNgay(){
		$now=getdate();
		return( $now["year"] . "-" . $now["mon"] . "-" . $now["mday"]); 
	}
	public function CongNgay(){ // cộng lên một tuần
		$today = date('Y-m-d');
		$week = strtotime(date("Y-m-d", strtotime($today)) . " +1 week");
   		$week = strftime("%Y-%m-%d",$week);
		return($week ); 
	}
	public function getURL(){
		$pageURL = 'http';
		if (!empty($_SERVER['HTTPS'])) {if($_SERVER['HTTPS'] == 'on'){$pageURL .= "s";}} 
			$pageURL .= "://";
		if ($_SERVER["SERVER_PORT"] != "80") {
			$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
		} else {
			$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
		}
		$this->session->set_userdata("S_URL",$pageURL );
 	}
	  


	public	function send_email($msg,$to,$subj) {
			include("class.phpmailer.php");  
			include("class.smtp.php"); 
			//$msg = 'Hello World';
			//$subj = 'test mail message';
			//$to = 'chancntt09@gmail.com';
			$from = 'chancntt09@gmail.com';
			$from_name = 'Thương mai điện tử'; 
			$mail = new PHPMailer();
			$mail->IsSMTP();
			$mail->SMTPAuth = true;
			$mail->SMTPDebug  = 1;
			$mail->SMTPSecure = 'ssl';
			//$mail->Host = "ssl://smtp.gmail.com";
			$mail->Host = 'smtp.gmail.com';
			$mail->Port = 465  ;  
			$mail->Username = 'chancntt09@gmail.com';  
			$mail->Password = 'thangboss00';
			$mail->SMTPKeepAlive = true;  
			$mail->Mailer = "smtp";     
			$mail->CharSet = "utf-8";
			$mail->IsHTML=true;
			$mail->SetFrom($from, $from_name);
			$mail->Subject = $subj;
			$mail->Body = $msg;
			$mail->AddAddress($to);
			if(!$mail->Send()) {
				return true;
				 
			} else {
				return false; 
			}
		
		}

}